import java.io.IOException;

/**
 * User: rmikhaylenko mirusnet@gmail.com
 * Date: 29/05/13
 * Time: 17:14
 */
public class Shutdown {
    private static long shutdownTime = 0;

    public static void shutdown(long shutdownTime) {
        if ((shutdownTime != 0) && (System.currentTimeMillis() > shutdownTime)) {
            try {
                Runtime.getRuntime().exec("shutdown -s -t 60");
                //Runtime.getRuntime().exec("rundll32.exe user32.dll, LockWorkStation");
                System.out.println(shutdownTime);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    public static void showAlert(long shutdownTime) {
        if (shutdownTime != 0) {
            System.out.println("REMINDER: Shutdown in " + Math.round((shutdownTime - System.currentTimeMillis()) / 60000) + " minutes");
        }
    }

    public static long getShutdownTime() {
        return shutdownTime;
    }

    public static void setShutdownTime() {
        shutdownTime = (shutdownTime == 0) ? 5 * 60 *1000 + System.currentTimeMillis() : shutdownTime + 5 * 60 * 1000;
    }

    public static void setShutdownTime(long minutes) {
        shutdownTime = (minutes == 0) ? 0 : System.currentTimeMillis() + minutes * 60 * 1000;
    }
}
